﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace QSSilverlightCSharp
{
    /// <summary>
    /// This is a simple helper to navigate between various sample pages. It should not be used in production.
    /// </summary>
	public static class Utils
	{
        private static readonly Dictionary<Type, UserControl> controls = new Dictionary<Type, UserControl>();
		public static void NavigateToPage<TControl>() where TControl : UserControl,new()
		{
		    TControl userControl;
		    var type = typeof (TControl);
		    if (controls.ContainsKey(type))
		    {
		        userControl = (TControl) controls[type];
		    }
		    else
		    {
		        userControl = new TControl();
		        controls.Add(type, userControl);
		    }
		    var root = (Control) Application.Current.RootVisual;
		    var contentHolder = (Grid) root.FindName("ContentHolder");
		    contentHolder.Children.Clear();
		    contentHolder.Children.Add(userControl);
		}
	}
}
